import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class thiepdientu extends MIDlet implements CommandListener
{

protected Display hienthi;
private Command ok,thoat, tiep, quaylai, lamlai; 
private Form form,form1,form2,form3;
private Alert thongbao;
private TextField hoten, ngaysinh, dienthoai, diachi, hotennguoiyeu, ngaysinhnguoiyeu, diachinguoiyeu, dienthoainguoiyeu;

public thiepdientu()
{
hienthi = Display.getDisplay(this);
form = new Form("Thiep Dien Tu");
form1 = new Form("Thong Tin Cua Ban");
form2 = new Form("Thong Tin Nguoi Yeu Cua Ban");
form3 = new Form("Chuc Mung");
thoat = new Command("Thoat", Command.EXIT, 1); 
ok = new Command("Xong", Command.OK, 1);
tiep = new Command("Tiep", Command.OK, 2);
quaylai = new Command("Quay lai",Command.BACK, 2);
form.addCommand(thoat); 
form.addCommand(ok); 
form1.addCommand(tiep);
form1.addCommand(quaylai);
form2.addCommand(tiep);
form2.addCommand(quaylai);
form3.addCommand(thoat);
lamlai = new Command("Lam lai",Command.BACK,1);
form3.addCommand(lamlai);
form.append("Chao Ban !");      
form.append("Ban hay dien day du thong tin ben duoi va nhan OK nha !");
hoten = new TextField("Ho va ten:", "", 32, TextField.ANY);
form.append(hoten);
ngaysinh = new TextField("Ngay sinh", null, 32, TextField.ANY);   
form.append(ngaysinh);
diachi = new TextField("Dia chi:", null, 32, TextField.ANY);   
form.append(diachi);
dienthoai = new TextField("So Dien Thoai:", null, 32, TextField.PHONENUMBER);   
form.append(dienthoai);
hotennguoiyeu = new TextField("Ten Nguoi Yeu:", null, 32, TextField.ANY);   
form.append(hotennguoiyeu);
ngaysinhnguoiyeu = new TextField("Ngay Sinh Nguoi Yeu:", null, 32, TextField.ANY);   
form.append(ngaysinhnguoiyeu);
diachinguoiyeu = new TextField("Dia chi Nguoi Yeu:", null, 32, TextField.ANY);   
form.append(diachinguoiyeu);
dienthoainguoiyeu = new TextField("So Dien Thoai Nguoi Yeu:", null, 32, TextField.PHONENUMBER);   
form.append(dienthoainguoiyeu);
hienthi.getDisplay(this);
form.setCommandListener(this);
form1.setCommandListener(this);
form2.setCommandListener(this);
form3.setCommandListener(this);
}
protected void startApp() 
{  
	hienthi.setCurrent(form);
}
protected void pauseApp() {}
protected void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s)
{
	if(c == thoat)
	{
		destroyApp(true);
		notifyDestroyed();
	}
	if(c == ok)
	{
		if(hoten.size() == 0)
		{
			thongbao = new Alert("Thong bao","Ban phai dien Ho ten cua Ban !",null,AlertType.INFO);
			thongbao.setTimeout(2000);
			hienthi.setCurrent(thongbao,form);    
		}
		else if(ngaysinh.size() == 0)
		{
			thongbao = new Alert("Thong bao","Ban phai dien Ngay sinh cua Ban !",null,AlertType.INFO);
			thongbao.setTimeout(2000);
			hienthi.setCurrent(thongbao,form);    
		}
		else if(diachi.size() == 0)
		{
			thongbao = new Alert("Thong bao","Ban phai dien Dia chi cua Ban !",null,AlertType.INFO);
			thongbao.setTimeout(2000);
			hienthi.setCurrent(thongbao,form);    
		}
		else if(dienthoai.size() == 0)
		{
			thongbao = new Alert("Thong bao","Ban phai dien So dien thoai cua Ban !",null,AlertType.INFO);
			thongbao.setTimeout(2000);
			hienthi.setCurrent(thongbao,form);    
		}
		else if(hotennguoiyeu.size() == 0)
		{
			thongbao = new Alert("Thong bao","Ban phai dien Ho ten cua Nguoi Yeu Ban !",null,AlertType.INFO);
			thongbao.setTimeout(2000);
			hienthi.setCurrent(thongbao,form);    
		}
		else if(ngaysinhnguoiyeu.size() == 0)
		{
			thongbao = new Alert("Thong bao","Ban phai dien Ngay sinh cua Nguoi Yeu Ban !",null,AlertType.INFO);
			thongbao.setTimeout(2000);
			hienthi.setCurrent(thongbao,form);    
		}
		else if(diachinguoiyeu.size() == 0)
		{
			thongbao = new Alert("Thong bao","Ban phai dien Dia chi cua Nguoi Yeu Ban !",null,AlertType.INFO);
			thongbao.setTimeout(2000);
			hienthi.setCurrent(thongbao,form);    
		}
		else if(dienthoainguoiyeu.size() == 0)
		{
			thongbao = new Alert("Thong bao","Ban phai dien So dien thoai cua Nguoi Yeu Ban !",null,AlertType.INFO);
			thongbao.setTimeout(2000);
			hienthi.setCurrent(thongbao,form);    
		}
		else 
		{
			form1.deleteAll();
			form1.append("Ho Ten:\n");
			form1.append(hoten.getString()+"\n");
			form1.append("Ngay Sinh:\n");
			form1.append(ngaysinh.getString()+"\n");
			form1.append("Dia Chi:\n");
			form1.append(diachi.getString()+"\n");
			form1.append("Dien Thoai:\n");
			form1.append(dienthoai.getString()+"\n");
			hienthi.setCurrent(form1);
		}
	}
	if((c == tiep)&&(hienthi.getCurrent() == form2))
	{
		form3.deleteAll();
		form3.append("Chuc 2 ban ");
		form3.append(hoten.getString());
		form3.append("va ");
		form3.append(hotennguoiyeu.getString());
		form3.append("Tram Nam Hanh Phuc !");		
		hienthi.setCurrent(form3);		
	}
	if((c == tiep)&&(hienthi.getCurrent() == form1))
	{
		form2.deleteAll();
		form2.append("Ho Ten Nguoi Yeu Ban:\n");
		form2.append(hotennguoiyeu.getString()+"\n");
		form2.append("Ngay Sinh Nguoi Yeu Ban:\n");
		form2.append(ngaysinhnguoiyeu.getString()+"\n");
		form2.append("Dia Chi Nguoi Yeu Ban:\n");
		form2.append(diachinguoiyeu.getString()+"\n");
		form2.append("Dien Thoai Nguoi Yeu Ban:\n");
		form2.append(dienthoainguoiyeu.getString()+"\n");
		hienthi.setCurrent(form2);
	}
	if((c == quaylai)&&(hienthi.getCurrent()== form1))
	{
		hienthi.setCurrent(form);
	}
	else if((c == quaylai)&&(hienthi.getCurrent()== form2))
	{
		hienthi.setCurrent(form1);
	}
	else if(c == lamlai)
	{
		hoten.setString("");
		ngaysinh.setString("");
		ngaysinhnguoiyeu.setString("");
		diachi.setString("");
		diachinguoiyeu.setString("");
		dienthoai.setString("");
		dienthoainguoiyeu.setString("");
		hotennguoiyeu.setString("");
		hienthi.setCurrent(form);
	}
}
}